public class MySingleList implements Ilist{
    static class ListNode{
        private int val;
        private ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
        //因为不知道下一个节点是谁，所以这里的构造函数的参数里不写next。
    }

    public ListNode head;//表示当前链表的头节点
    public void CreateList(){
        ListNode node1 = new ListNode(11);
        ListNode node2 = new ListNode(22);
        ListNode node3 = new ListNode(33);
        ListNode node4 = new ListNode(44);
        //这些数据之间没有连续性

        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        //node4已经是最后一个节点了，不需要管最后一个next

        this.head = node1;//这样可以从第一个节点开始去遍历我们的数组
    }

    @Override
    public void addFirst(int data) {
        ListNode node = new ListNode(data);
        if(head == null){
            head = node;//相当于插入进一个空的链表
        }else{
            node.next = head;
            head = node;
        }
    }

    @Override
    public void addLast(int data) {
        ListNode node = new ListNode(data);
        //表示链表为空
        if(head == null) {
            head = node;
            return;
        }
        //找到链表的尾巴
        ListNode cur = head;
        while (cur.next != null) {
            cur = cur.next;
        }
        cur.next = node;
    }

    @Override
    public void addIndex(int index, int data) {

    }

    @Override
    public boolean contains(int key) {
        ListNode cur1 = head;
        while(cur1 != null){
            if(cur1.val == key){
                return true;
            }
            cur1 = cur1.next;
        }
        return false;
    }

    @Override
    public void remove(int key) {

    }

    @Override
    public void removeAllKey(int key) {

    }

    @Override
    public int size() {
        ListNode cur = head;
        int count = 0;
        while(cur != null){
            cur = cur.next;
            count++;
        }
        return count;
    }

    @Override
    public void clear() {

    }

    @Override
    public void display() {
        ListNode cur = head;
        while(cur != null){
            System.out.print(cur.val+" ");
            cur = cur.next;
        }
        System.out.println();
    }
}
